<?php
/**
 * Created by PhpStorm.
 * User: divya
 * Date: 2018/7/30
 * Time: 下午5:21
 */

namespace app\api\model;


class Category extends BaseModel
{
    public static function getCatetory(){
        $rs = self::all([],'img');
        return $rs;
    }
    public function img(){
        return $this->belongsTo('Image','topic_img_id','id');
    }
    public function products(){
        return $this->hasMany('Product','category_id','id');
    }
    public static function getCatetoryById($id){
        $rusult = self::with(['products'])->find($id);
        return $rusult;
    }
}